import React from "react";
import {
    Switch,
    Route,
    Redirect
} from 'react-router-dom'
import BeforeEach from "./BeforeEach";

const RouterView = (props:any) => {
    return (
        <Switch>
            {
                props.routes&&props.routes.map((item:any,index:any)=>{
                    return item.path?<Route 
                    path={item.path}
                    key={index} 
                    // render={(props)=><item.component {...props} routes={item.children}/>}
                    render={(props)=><BeforeEach {...props} component={item.component} routes={item.children}></BeforeEach>}
                    />
                    :<Redirect {...item} key={index} exact/>
                })
            }
        </Switch>
    )
};

export default RouterView